
import os 
import sys
def remove_plane(input_ply, output_ply):
    cmd = f"python remove_plane.py {input_ply} {output_ply} --mode auto --distance_threshold 10 --visualize --vis_color original"
    os.system(cmd)

def denoise_point_cloud(input_ply, output_ply):
    tmp_file1 = 'tmp1.ply'
    tmp_file2 = 'tmp2.ply'
    cmd = f"python denoise_point_cloud.py {input_ply} {tmp_file1} --method voxel --voxel_size=0.0001"
    os.system(cmd)
    cmd = f"python denoise_point_cloud.py {tmp_file1} {tmp_file2} --method sor --nb_neighbors 20 --std_ratio 2.0"
    os.system(cmd)
    cmd = f"python denoise_point_cloud.py {tmp_file2} {output_ply} --method ror --nb_points 20 --radius 20"
    os.system(cmd)
    os.system(f"rm {tmp_file1} {tmp_file2}")

input_root = '/home/xfzhou/workspace/data/exp1/orig'
output_root = '/home/xfzhou/workspace/data/exp1/s1_remove_plane'
os.makedirs(output_root, exist_ok=True)
for file in os.listdir(input_root):
    if file.endswith('.ply'):
        input_ply = os.path.join(input_root, file)
        output_ply = os.path.join(output_root, file)
        remove_plane(input_ply, output_ply)

input_root = '/home/xfzhou/workspace/data/exp1/s1_remove_plane'
output_root = '/home/xfzhou/workspace/data/exp1/s2_denoise'
os.makedirs(output_root, exist_ok=True)
for file in os.listdir(input_root):
    if file.endswith('.ply'):
        input_ply = os.path.join(input_root, file)
        output_ply = os.path.join(output_root, file)
        denoise_point_cloud(input_ply, output_ply)

os.system("python pair_icp.py")
